package com.jinghong.registerlogin.mapper;

import com.jinghong.registerlogin.model.pojo.Question;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.springframework.core.annotation.Order;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:QuestionMapper
 * Package:com.jinghong.registerlogin.mapper
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2024/5/17 17:44
 * Version:1.0
 */
@Mapper
public interface QuestionMapper {
    //增

    /**
     * 新增题目
     * @param question 问题
     */
    @Insert("insert into `register_login`.question(content, type, option_num, a,b,c,d,e,score, answer, detail, user_id, creat_time, update_time) " +
            "values (#{content},#{type},#{optionNum,jdbcType=INTEGER},#{a,jdbcType=VARCHAR},#{b,jdbcType=VARCHAR},#{c,jdbcType=VARCHAR},#{d,jdbcType=VARCHAR},#{e,jdbcType=VARCHAR},#{score},#{answer},#{detail},#{userId},now(),now())")
    @SelectKey(before = false,keyProperty = "id",resultType = Integer.class,statement = "SELECT LAST_INSERT_ID()")
    void insert(Question question);


    /**
     * 批量添加题目
     * @param questions 问题集合
     */
    void bulkInsert(List<Question> questions);


    //删
    /*删除题目*/
    void delete(List<Integer> ids);


    //改

    /**
     *  更改题目信息
     * @param question 问题信息
     */
    void update(Question question);


    //查

    /**
     * 题目的条件查询
     * @param userId
     * @param content
     * @param type
     * @param score
     * @param begin
     * @param end
     * @return
     */
    List<Question> select(Integer userId, String content, Short type, Integer score, LocalDateTime begin, LocalDateTime end);


    /**
     * 编辑题目时数据回显
     * @param id 题目id
     * @return 题目
     */
    @Select("select * from `register_login`.question where id = #{id}")
    Question getById(Integer id);


    /**
     * 根据内容和题目类型去重
     * @param content 题目内容
     * @param type  题目类型
     * @return 题目对象
     */
    @Select("select * from `register_login`.question where content = #{content} and type = #{type}")
    Question getByContentAndType(String content,Short type);

    /**
     *
     * @param ids 问题ids
     * @return questions 问题集合
     */
    List<Question> bulkGet(List<Integer> ids);

    void bulkUpdate(List<Question> questions);
}
